<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script type="text/javascript">

    var num1 = "1.4";

    var num2 = "2.1";

    //进行类型的转换:把字符串转成整数

    //var result = parseInt(num1) + parseInt(num2);

    //可以在转换前进行判断，非数字返回true
    if (isNaN(num1) == false) {
        //将字符串转成浮点数
        var result = parseFloat(num1) + parseFloat(num2);
        //按字符串拼接
        document.write(result + "<br/>");
    }else {
        document.write("数字转换失败" + "<br/>");
    }

</script>
</body>
</html>